<?php
namespace app\api\service;
/**
 * Feedback Service
 * User: zng
 * Date: 2020/01/16
 * Time: 16:25
 */
use app\api\model\system\Feedback as FeedbackModels;
use app\exceptions\OrdinaryException;

class Feedback {

    /**
     * 反馈意见存储
     * @param array $data 数据包
     * @throws OrdinaryException
     */
    public function storage( array $data )
    {
        $feedback = FeedbackModels::create($data, ['uid', 'opinion']);
        if ( $feedback->isEmpty() ) {
            throw new OrdinaryException('新增失败');
        }
        if ( $data['image_url'] ) {
            $images = [];
            foreach ( $data['image_url'] as $_image ) {
                $images[] = ['image_url'=>$_image];
            }
            $feedback->image()->saveAll($images);
        }
        return success();
    }

}